package file;

public class Printer {
	
	private int index = 1;
	
	public synchronized void print(int i){
		//2)在打印类Printer中编写打印数字的方法print(int i)，3的倍数就使用wait()方法等待，
		//否则就输出i，使用notifyAll()进行唤醒其它线程。
		try {
			Thread.sleep(100L);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
		
		//判断index是否能被3整除
		while(index%3==0){
			try {
				wait();
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
		}
		
		System.out.println(i);
		index++;
		//唤醒字母线程
		this.notifyAll();
	}
	public synchronized void print(char c){
		try {
			Thread.sleep(100L);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
		//判断index是否不能被3整除
		while(index%3!=0){
			try {
				wait();
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
		}
		
		System.err.println(c);
		index++;
		//唤醒数字线程
		this.notifyAll();
	}
	

	public Printer(int index) {
		super();
		this.index = index;
	}

	public Printer() {
		super();
	}

}
